import React, { Component } from 'react';
class Todo extends Component {
    constructor(props) {
        super(props);
    }
    state = {}
    collectionItem = () => {
        // 搜集input中的值
        console.log(this.msgInput.value);
        // 整理格式去除首尾空格
        const inpVal = this.msgInput.value.trim();
        // 判读是否是空串
        if (!inpVal) {
            return
        }
        // 将数据添加到list
        // console.log(this.props.add);
        this.props.add(inpVal);
        // 清空
        this.msgInput.value = '';

    }
    render() {
        return (
            <div>
                <h1>todo</h1>
                <input type="text" ref={input => this.msgInput = input} />
                <button onClick={this.collectionItem}>添加</button>
            </div>
        );
    }
}

export default Todo;
